/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.重新排列日志文件;



import java.util.Collections;
import java.util.LinkedList;

public class Main {
    public static void main(String arg[]){//main--来自高金磊

        new Main().reorderLogFiles(new String[]{"a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo","a2 act car"});
    }

    //err
    public String[] reorderLogFiles(String[] logs) {
        //将数字和字符串日志分开
        LinkedList<String> numdata=new LinkedList<>();
        LinkedList<String> strdata=new LinkedList<>();
        for (String log : logs) {
            String[] middle=log.split(" ");
            boolean flag=true;
            int i;
            if (middle.length<2){
                flag=false;
                strdata.addLast(log);
                break;
            }
            for (i = 1; i < middle.length&&flag; i++) {
                for (char c : middle[i].toCharArray()) {
                    if (c<='9'&&c>='0'){

                    }
                    else {
                        flag=false;
                        strdata.addLast(log);
                        break;
                    }
                }
            }
            if (flag){
                numdata.addLast(log);
            }
        }
        Collections.sort(strdata, (a,b)->(a.substring(a.indexOf(" ")).compareTo(b.substring(b.indexOf(" ")))-1));
        for (String numdatum : numdata) {
            strdata.addLast(numdatum);
        }
        int i=0;
        for (String strdatum : strdata) {
            logs[i++]=strdatum;
        }
        return logs;
    }
}
